package de.tabuma.soapforms.soapproject.view;

import de.tabuma.customer.entity.*;
import de.tabuma.soapforms.*;
import de.tabuma.soapforms.soapproject.entity.*;
import de.tabuma.lib.tabumaview;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

/**
 *
 * @author alefen
 */
public class update extends tabumaview {

    public update(String servlet, Hashtable parameter) {
        super(servlet, parameter);
    }

    @Override
    public void processRequest(ServletContext context, HttpServletRequest request, HttpServletResponse response, PrintWriter out) {
        String next = "Next";
        String cancel = "Cancel";
        String projectUrl = "url";
        String projectMethod = "method";
        String name = "name";
        String customer = "customer";
        List<Customer> cList = (List<Customer>) request.getAttribute(constants.customerList);

        SoapProject soapProject = (SoapProject) request.getAttribute(constants.soapProject);

        out.println("<div class=\"contentBoxed\">");
        out.println("<div class=\"contentContent\">");
        out.println(this.getFormBeginn(null));
        out.println(this.getHiddenAsAttribute());
        out.println(printHiddenField(constants.soapProjectId, (String) request.getAttribute(constants.soapProjectId)));
        out.println(printHiddenField(constants.updateSoapProject1, "true"));

        out.println("<div class=\"cols\">");
        out.println(view.printForm1(name, constants.soapProjectName, soapProject.getName()));
        out.println("<div class=\"col2\">");
        out.println("<div class=\"col2_head\">"+customer+"</div>");
        out.println("<div class=\"col2_content\">");
        out.println("<select name=\""+constants.customerId+"\">");
        for(int i=0;i<cList.size();i++) {
            Customer c = cList.get(i);
            if(c.getId().intValue()==soapProject.getCustomerId()) {
                out.println("<option value=\""+c.getId().intValue()+"\" selected>"+c.getName()+"</option>");
            }
            else {
                out.println("<option value=\""+c.getId().intValue()+"\">"+c.getName()+"</option>");
            }
        }
        out.println("</select>");
        out.println("</div>");
        out.println("</div>");
        out.println("<div class=\"col1\">");
        out.println("<div class=\"col1_head\">"+projectUrl+"</div>");
        out.println("<div class=\"col1_content\">"+soapProject.getWsdlUrl()+"</div>");
        out.println("</div>");
        out.println("<div class=\"col2\">");
        out.println("<div class=\"col2_head\">"+projectMethod+"</div>");

        List<String> methodList = (List<String>) request.getAttribute(constants.soapProjectMethodList);

        out.println("<div class=\"col2_content\">");
        out.println("<select name=\""+constants.soapProjectMethod+"\">");
        for(int i=0;i<methodList.size();i++) {
            String method = methodList.get(i);
            if(method.equals(soapProject.getMethod())) {
                out.print("<option value=\""+method+"\" selected>"+method+"</option>");
            }
            else {
                out.print("<option value=\""+method+"\">"+method+"</option>");
            }
        }
        out.println("</select></div>");
        out.print("</div>");
        out.print("</div>");

        out.println("<input type=\"submit\" class=\"button\" name=\""+constants.next+"\" value=\""+next+"\"/>");
        out.println("<input type=\"submit\" class=\"button\" name=\""+constants.cancel+"\" value=\""+cancel+"\"/>");
        out.println(this.getFormEnd());
        out.println("</div>");
        out.println("</div>");
    }
}